# Contributor: Sergei Lukin <sergej.lukin@gmail.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=libevent
pkgver=2.1.12
_pkgver=$pkgver-stable
pkgrel=7
pkgdesc="An event notification library"
url="https://libevent.org/"
arch="all"
license="BSD-3-Clause"
options="!check" # regression tests failed
depends_dev="python3"
makedepends="$depends_dev openssl-dev>3"
subpackages="$pkgname-static $pkgname-dev"
source="https://github.com/libevent/libevent/releases/download/release-$_pkgver/libevent-$_pkgver.tar.gz"
builddir="$srcdir/$pkgname-$_pkgver"

# secfixes:
#   2.1.8-r0:
#     - CVE-2016-10195
#     - CVE-2016-10196
#     - CVE-2016-10197

prepare() {
	default_prepare
	update_config_sub

	sed -i '1s|^#!/usr/bin/env python$|#!/usr/bin/python3|' event_rpcgen.py
	# help provides tracing work out correctly
	sed -i -e "s/@VERSION@/$pkgver-r$pkgrel/" *.pc.in
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc
	make
}

check() {
	make -j1 check
}

package() {
	make -j1 DESTDIR=$pkgdir install
}

dev() {
	replaces="libevent"
	default_dev
	mv "$pkgdir"/usr/bin "$subpkgdir"/usr/
}

static() {
	depends=""
	pkgdesc="$pkgdesc (static libraries)"
	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/*.a "$subpkgdir"/usr/lib
}

sha512sums="88d8944cd75cbe78bc4e56a6741ca67c017a3686d5349100f1c74f8a68ac0b6410ce64dff160be4a4ba0696ee29540dfed59aaf3c9a02f0c164b00307fcfe84f  libevent-2.1.12-stable.tar.gz"
